// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

import ALARM_API from '@admin/components/detail/DetailAlarm/store/API'
import ALARM_DEAL_API from '@admin/components/detail/DetailAlarm/store/deal/API'

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  async remoteOne({ state: { API, one } }) {
    const TIP = API.transTip(`查询违规的${CORE.MAP.ALARM}`)
    const obj = await ALARM_API.getOne({ id: one.messageId }, TIP)
    return transOne(obj, one)
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  async remoteEdit({ state: { API, one } }) {
    const obj = { id: one.messageId, dealType: +one.dealType, dealDesc: one.dealDesc }
    const TIP = API.transTip(one.TIP)
    const msg = await ALARM_DEAL_API.deal(obj, TIP)
    return msg
  },
}

// ============================== 转换方法 ============================== //

const transOne = (obj, one) => {
  return { ...one, alarm: obj }
}
